package com.gxa.finance.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.commons.R;
import com.gxa.finance.mapper.ServiceNodeMapper;
import com.gxa.common.pojo.ServiceNode;
import com.gxa.finance.service.ServiceNodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ServiceNodeServiceImpl extends ServiceImpl<ServiceNodeMapper, ServiceNode> implements ServiceNodeService {

    @Autowired
    private ServiceNodeMapper ServiceNodeMapper;

    //查询接口
    @Override
    public R findServiceNodeList(String serve,Integer price) {
        R r = new R();
        try{
            List<ServiceNode> ServiceNodeList = ServiceNodeMapper.findServiceNodeList(serve,price);
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(ServiceNodeList);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("网络开小差");
        }
        return r;
    }

    //新增接口
    @Override
    public R addServiceNode(ServiceNode ServiceNode) {
        R r = new R();
        int result = ServiceNodeMapper.insert(ServiceNode);
        if (result > 0) {
            r.setCode(200);
            r.setMsg("添加成功");
        }else {
            r.setCode(500);
            r.setMsg("系统出小差了，请联系管理员");
        }
        return r;
    }

    @Override
    public R delServiceNode(Integer id) {

        R r = new R();
        int result = ServiceNodeMapper.deleteById(id);

        if (result > 0) {
            r.setCode(200);
            r.setMsg("删除成功");
        }else {
            r.setCode(500);
            r.setMsg("系统出小差了，请联系管理员");
        }
        return r;

    }

    @Override
    public R updateServiceNode(ServiceNode ServiceNode) {
        R r = new R();
        int result = ServiceNodeMapper.updateById(ServiceNode);
        if (result > 0) {
            r.setCode(200);
            r.setMsg("修改成功");
        }else {
            r.setCode(500);
            r.setMsg("系统出小差了，请联系管理员");
        }
        return r;
    }
}
